import { defineStore } from 'pinia'
export interface SystemConfigStoreInterface {
  "ldap-enabled"?: boolean;
  systemPcUrl?: string;
  systemH5Url?: string;
  systemLogo?: string;
  systemName?: string;
  memberDefaultAvatar?: string;
  courseDefaultThumbs?: string[];
  departments?: any;
  resourceCategories?: any;
  resourceUrl?: ResourceUrlModel;
}

export const useSystemStore = defineStore('system', {
  state: (): SystemConfigStoreInterface => ({
    "ldap-enabled": false,
    systemPcUrl: undefined,
    systemH5Url: undefined,
    systemLogo: undefined,
    systemName: undefined,
    memberDefaultAvatar: undefined,
    courseDefaultThumbs: undefined,
    departments: undefined,
    resourceCategories: undefined,
    resourceUrl: undefined
  }),

  getters: {
    getLdapEnabled: (state) => state["ldap-enabled"],
    getSystemPcUrl: (state) => state.systemPcUrl,
    getSystemH5Url: (state) => state.systemH5Url,
    getSystemLogo: (state) => state.systemLogo,
    getSystemName: (state) => state.systemName,
    getMemberDefaultAvatar: (state) => state.memberDefaultAvatar,
    getCourseDefaultThumbs: (state) => state.courseDefaultThumbs,
    getDepartments: (state) => state.departments,
    getResourceCategories: (state) => state.resourceCategories,
    getResourceUrl: (state) => state.resourceUrl,
    getConfig: (state) => state,
  },

  actions: {
    // 保存配置动作
    saveConfigAction(payload: SystemConfigStoreInterface) {
      Object.assign(this, payload)
    },

    // 保存部门动作
    saveDepartmentsAction(payload: any) {
      this.departments = payload
    },

    // 保存分类动作
    saveCategoriesAction(payload: any) {
      this.resourceCategories = payload
    },

    // 设置配置
    setConfig(config: SystemConfigStoreInterface) {
      this.saveConfigAction(config)
    },

    // 设置LDAP配置
    setLdapConfig(config: any) {
      this["ldap-enabled"] = config.enabled
    },

  }
})